package com.example.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Date 2021/7/21 15:57
 * @Created by wangle
 * @Description 配置类，发布确认高级内容
 */
@Configuration
public class Confirmconfig {


    //交换机名字
    public  static  final  String  Confirm_exchangeName="confirm_exchange";

    //队列名
    public  static  final  String queuename=" confirm_queue";
    //routingkey
    public  static  final  String  routingkey="k1";
    //备份交换机
    public  static  final  String  backup_exchange="backup_exchange";
    //备份队列
    public  static  final  String backup_queue=" backup_queue";
    //警告队列
    public  static  final  String waring_queue=" waring_queue";
    //声明交换机
    @Bean("confirmExchange")
    public DirectExchange confirmExchange(){


        return  ExchangeBuilder.directExchange(Confirm_exchangeName).durable(true)
                .withArgument("alternate-exchange",backup_exchange).build();
    }



    @Bean("confirmQueue")
    public Queue confirmQueue(){

        return QueueBuilder.durable(queuename).build();
    }
    //绑定
    @Bean
    public Binding QueueBindingexchange(@Qualifier("confirmQueue") Queue queue,
                                        @Qualifier("confirmExchange") DirectExchange exchange){

        return BindingBuilder.bind(queue).to(exchange).with(routingkey);
    }

    //备份交换机声明
    @Bean("backupExchange")
    public FanoutExchange backupExchange(){


        return  new FanoutExchange(backup_exchange);
    }
    //备份队列
    @Bean("backupQueue")
    public Queue backupQueue(){

        return QueueBuilder.durable(backup_queue).build();

    }

    @Bean("waringQueue")
    public Queue waringQueue(){

        return QueueBuilder.durable(waring_queue).build();

    }


    //绑定
    @Bean
    public Binding backQueueBindingbackupexchange(@Qualifier("backupQueue") Queue queue,
                                        @Qualifier("backupExchange") FanoutExchange exchange){

        return BindingBuilder.bind(queue).to(exchange);
    }
    //绑定
    @Bean
    public Binding waringQueueBindingbackupexchange(@Qualifier("waringQueue") Queue queue,
                                                  @Qualifier("backupExchange") FanoutExchange exchange){

        return BindingBuilder.bind(queue).to(exchange);
    }



}
